﻿using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.HVAC.DuctTerminalTag;
using YArchitech.HVAC.LevelIndependentTag;
using YArchitech.Revit;
using HYCodeBase.WinForm;

namespace YArchitech.HVAC
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class DuctTerminalTagCommand : HYNoTranExternalCommand
	{
		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		public override Result HYExecute()
		{
			Transaction transaction = new Transaction(base.Doc, "添加共享参数");
			transaction.Start();
			new MarkOperation().AddAllShareParametes(base.UiApp);
			transaction.Commit();
			new Transaction(base.Doc, "风口标注");
			if (DuctTerminalTagCommand.wndRevit == null)
			{
				Process currentProcess = Process.GetCurrentProcess();
				IntPtr mainWindowHandle = currentProcess.MainWindowHandle;
				DuctTerminalTagCommand.wndRevit = new WindowHandle(currentProcess.MainWindowHandle);
			}
			this.frm = new FrmDuctTerminalTag();
			this.frm.Show(DuctTerminalTagCommand.wndRevit);
			this.frm.commFont.LeadDistance = MarkPipeLevelUtility.GetTansferDistance(this.frm.commFont.LeadDistance, 30);
			this.frm.commFont.TubeDistance = MarkPipeLevelUtility.GetTansferDistance(this.frm.commFont.TubeDistance, 30);
			new DuctTerminalTagOperate(base.Doc, this.frm).Execute();
			this.frm.Close();
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public static WindowHandle wndRevit;

		private FrmDuctTerminalTag frm;
	}
}
